package com.oig.sys.oauth.handler;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;

public abstract class AbstractAuthenticationSuccessEventHandler implements ApplicationListener<AuthenticationSuccessEvent> {


    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent event) {
        Authentication authentication = (Authentication) event.getSource();
        if (ObjectUtils.isNotEmpty(authentication.getAuthorities())) {
            handle(authentication);
        }
    }



    /**
     * 处理登录成功方法
     * @param authentication 登录对象
     */
    public abstract void handle(Authentication authentication);
}
